var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
require('./database/connect.js')//引入数据库连接文件
var {checkToken}=require('./utils/authToken.js')//引入token验证函数

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var cartRouter=require('./routes/cart')

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/cart', (req, res, next) => {//解析token
    console.log(req.headers);
    checkToken(req,res,next)//调用验证函数
},cartRouter)

module.exports = app;
